<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>公告</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">							
			.fixedBox{					
				<!-- white-space: nowrap;	 -->
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}		
		</style>				
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>			
			var tt = "";
			var gt = "";
			var jt = "";
			var dt = "";
			var k = "0";			
			window.onload = function() {
			var day = new Date();
			gt = day.getTime();			
			jt = Math.round(gt/1000);
			//dt = jt;
			mymonth = day.getMonth()+1;
			myday = day.getDate();
			if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
			if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
			tt = day.getFullYear() + "-" + mymonth + "-" + myday;
			dt = tt;			
			getSource();
			changeStyle();
			}
								
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource();				
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {				
				var obj = document.getElementById("towrite");
				obj.style.left= "0px";   //右侧左边位置
				obj.style.width= "500px";  //右侧宽度
				obj.style.fontSize="12px";	//右侧字体					
			}
			
		function createXmlHttp() {
			if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();				
			} else {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");				
			}
		}
		
		function getSource() {
			div = document.getElementById('towrite');		
			div.innerHTML = '<font size="3">公告&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
			var url11 = "https://flash-api.xuangubao.cn/api/surge_stock/stocks?normal=true&uplimit=true"; 
			var url12 = "https://flash-api.xuangubao.cn/api/surge_stock/stocks?date=" + tt.replace(/-/g,"") + "&normal=true&uplimit=true";
			               
			var url21 = "https://flash-api.xuangubao.cn/api/pool/detail?pool_name=limit_up";
			var url22 = "https://flash-api.xuangubao.cn/api/pool/detail?pool_name=limit_up&date=" + tt; 
            //var url21 = "https://flash-api.xuangubao.cn/api/pool/detail?pool_name=limit_up&date=2021-11-04"; 
			var url31 = "http://goserver.huanshoulv.com/aimapp/surgeLimit/surgeLimitList?page=1&type=1&sort_type=-1&page_count=5000&channel=hsl-app&ts=1560867041083&sign=8e4ef91d04fca0817e2b21e9c816f14e";
			var url32 = "http://goserver.huanshoulv.com/aimapp/surgeLimit/surgeLimitHistory?sort_type=-1&history_type=1&stock_type=0&sort_field_name=px_change_rate&page=1&type=1&page_count=5000&ts=1560872187660&sign=abb625fb40ab53893b4347cc4b32adef&channel=hsl-app&date=" + tt.replace(/-/g,"");
			
			var url1 = url11;
			var url2 = url21;
			var url3 = url31;
			if(k == "1" )
			{
			  url1 = url12;
			  url2 = url22;
			  url3 = url32;
			}
			
			if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();				
			} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");				
			}
			xmlHttp1.onreadystatechange = writeSource;				
			xmlHttp1.open("GET", url1, true);
			xmlHttp1.send(null);			

			if (window.XMLHttpRequest) {
				xmlHttp2 = new XMLHttpRequest();				
			} else {
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");				
			}
			xmlHttp2.onreadystatechange = writeSource;				
			xmlHttp2.open("GET", url2, true);
			xmlHttp2.send(null);			

			if (window.XMLHttpRequest) {
				xmlHttp3 = new XMLHttpRequest();				
			} else {
				xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");				
			}
			xmlHttp3.onreadystatechange = writeSource;				
			xmlHttp3.open("GET", url3, true);
			xmlHttp3.send(null);						
		}
		
		function cDayFunc(dp) 
		{ 
			var date = dp.cal.getNewDateStr();            
			BookingRmk(date);//调用其它函数并带上参数                
		}
		
		function BookingRmk(date)
		{         
			tt = date;
			gt = new Date(tt).getTime();
			jt = Math.round(gt/1000);
			k = 0;
			if(dt != tt)
			{			
				k = 1;
			}			
			getSource();
		}
		
		function changeCss(obj,id){				
			var alist = document.getElementById(id).getElementsByTagName("a");					
			for(var i = 0; i < alist.length; i++){				
				if(alist[i] == undefined){
					break;
				}
				alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				alist[i].style.color = "#fff"; //给所有a标签赋原色
			}
			obj.style.color = "#00FFFF"; //令当前标签高亮				
		}
		
		function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
		};
			
		function writeSource() { 			
			if (xmlHttp1.readyState == 4 && xmlHttp2.readyState == 4 && xmlHttp3.readyState == 4) {                  	
				var data1 = xmlHttp1.responseText
				data1 = data1.replace(/ /g,"").replace(/(.SZ)|(.SS)/g,"");	
				
				var data2 = xmlHttp2.responseText
				data2 = data2.replace(/ /g,"").replace(/(.SZ)|(.SS)/g,"");
				
				var data3 = xmlHttp3.responseText
				data3 = data3.replace(/ /g,"");
				//document.write(data3);				
				
				//热点解读					
				data1 = data1.replace(/(\[\[).*?(?=\],\[)/g,
				function(word){ 
					str = word.match(/\[\[(\S*)/)[1];
					if(str.indexOf('"id":-1,"name":"公告"') > -1)
					{
						ss = str.replace(/\[\{.*?\}\]/,"");
						return '[{' + '"code":' + ss.split(',')[0] + ',"prod_name":' + ss.split(',')[1] + ',"zf":' + ss.split(',')[3] + ',"xq":' + '"' + ss.split(',"')[2].match(/(\S*)\",/)[1] + '"' + ',"lb":' + '"' + ss.split(',"')[3].match(/(\S*)\",/)[1] + '"';
					}
					else
					{
						return "";
					}
				});				
				data1 = data1.replace(/(\],\[).*?((?=\],\[)|(?=\]\]))/g,
				function(word){ 
					str = word.match(/\[(\S*)/)[1];
					if(str.indexOf('"id":-1,"name":"公告"') > -1)
					{
						ss = str.replace(/\[\{.*?\}\]/,"");						
						return '},{' + '"code":' + ss.split(',')[0] + ',"prod_name":' + ss.split(',')[1] + ',"zf":' + ss.split(',')[3] + ',"xq":' + '"' + ss.split(',"')[2].match(/(\S*)\",/)[1] + '"' + ',"lb":' + '"' + ss.split(',"')[3].match(/(\S*)\",/)[1] + '"';					
					}
					else
					{
						return "";
					}
				});
				data1 = data1.replace(/\]\]\}\}/g,"}]}}").replace(/:\},/g,":[");
				
				//涨幅				
				data1 = data1.replace(/(\"zf\":).*?(?=,)/g, function(word){ 				
					str = word.match(/\"zf\":(\S*)/)[1]; 					
					return '\"zf\":"' + keepTwoDecimal(str*100) + '"';
				});  							
				//document.write(data1);

				//选股宝
				var html2 = "";
				var ss2 = data2.split('stock_chi_name');  
				for(var i = 0; i < ss2.length; i++){					
					if(ss2[i].indexOf('"plate_name":"公告"') > -1)
					{
						//alert(ss2[i]);
						var hh = ss2[i].match(/(\S*),"related_plates/)[1];
						html2 += '["mc' + hh + "],";
					}					
				}
				if(html2 != ""){
					html2 = html2 + "[";	
				}				
				else{
					html2 = "],[";
				}
				//document.write(html2);

				//换手率(基准)				
				var html3 = "";
				var hsl = "";	
				var xgb = "";	
				var rdjd = "";
				var ss3 = data3.split('],['); 
				for(var i = 1; i < ss3.length; i++){					
					if(ss3[i].indexOf('公告（') > -1)
					{
					
						var ggs = ss3[i];	
						if(ggs.indexOf("（") != -1 && ggs.indexOf("）") != -1){
							var l1 = ggs.indexOf("（");
							var l2 = ggs.indexOf("）");
							var ggs1 = ggs.substr(0,l1);
							var ggs2 = ggs.substr(l1,l2-l1);
							ggs2 = ggs2.replace(/,/g,"，")
							var ggs3 = ggs.substr(l2,ggs.length-l2); 
							ggs = ggs1 + ggs2 + ggs3;
						}
						//document.write(ggs);						
						var str = ggs.split(',');
						var dm = str[32];
						var mc = str[33];
						var zf = str[29];
						var lb = str[35];
						hsl = str[3];
												
						xgb = '"无"';
						var aa2 = html2.split('],['); //选股宝
						for(var i2 = 0; i2 < aa2.length; i2++){	
							if(aa2[i2].indexOf(dm) > -1)
							{
								xgb = aa2[i2].match(/stock_reason":(\S*)/)[1];
							}								 
						}						
						
						rdjd = '"无"';						
						var aa1 = data1.split('},{');//热点解读
						for(var i1 = 0; i1 < aa1.length; i1++){	
							if(aa1[i1].indexOf(dm) > -1)
							{
								rdjd = aa1[i1].match(/xq":(\S*),"lb/)[1];
							}								 
						}
						if(xgb == rdjd)	{
							xgb = '"无"';	
						}
						html3 += "{" + '"code":' + dm + ',"mc":' + mc + ',"zf":' + zf + ',"lb":' + lb + ',"hsl":' + hsl + ',"xgb":' + xgb + ',"rdjd":' + rdjd + "},";
					}					
				}
				
				//热点解读(基准)
				hsl = '"无"';
				if(data1.indexOf('"items":}]}}')==-1)
				{				
					var sss = data1.split('items')[1].replace("}]}}","");	
					var rdjds = sss.split('},{');
					for(var j2 = 0; j2 < rdjds.length; j2++){
						if(rdjds[j2]!=""){					
							var dm =  rdjds[j2].match(/code":(\S*),"prod_name/)[1];
							var mc =  rdjds[j2].match(/prod_name":(\S*),"zf/)[1];
							var zf =  rdjds[j2].match(/zf":(\S*),"xq/)[1];
							var lb =  rdjds[j2].match(/lb":(\S*)/)[1];
							rdjd =  rdjds[j2].match(/xq":(\S*),"lb/)[1];						
							if(html3.indexOf(dm) == -1)
							{	
								xgb = '"无"';
								var aa2 = html2.split('],['); //选股宝
								for(var i2 = 0; i2 < aa2.length; i2++){	
									if(aa2[i2].indexOf(dm) > -1)
									{
										xgb = aa2[i2].match(/stock_reason":(\S*)/)[1];
									}								 
								}
								if(xgb == rdjd)	{
									xgb = '"无"';	
								}
								html3 += "{" + '"code":' + dm + ',"mc":' + mc + ',"zf":' + zf + ',"lb":' + lb + ',"hsl":' + hsl + ',"xgb":' + xgb + ',"rdjd":' + rdjd + "},";
							}						
						}					
					}
				}				
				
				//选股宝(基准)				
				rdjd = '"无"';				
				var xgbs = html2.split('],[');
				for(var j1 = 0; j1 < xgbs.length; j1++){
					if(xgbs[j1]!=""){
						var dm =  xgbs[j1].match(/symbol":(\S*),"stock_reason/)[1];						
						var mc = "";
						if(k == 0){
							mc =  xgbs[j1].match(/"mc":(\S*),"stock_type/)[1];
						}
						else{
							mc =  xgbs[j1].match(/"mc":(\S*),"surge_reason/)[1];
						}
						xgb = xgbs[j1].match(/stock_reason":(\S*)/)[1];																
						if(html3.indexOf(dm) == -1)
						{																			
							html3 += "{" + '"code":' + dm + ',"mc":' + mc + ',"zf":""' + ',"lb":' + '""' + ',"hsl":' + hsl + ',"xgb":' + xgb + ',"rdjd":' + rdjd + "},";
						}
					}					
				}			
								
				html3 = '{"data":[' + html3 + "]}";
				html3 = html3.replace("},]}","}]}");
				//document.write(html3);
								
				var transform_aa = [           
				{"tag":"ul", children:function(){return(json2html.transform(this.data, transform_bb));}}
				];
								
				var transform_bb = [
				{"tag":"li", children:[				
				//{"tag": "b", "html":"<a href='http://www.treeid/code_${code}' onclick='changeCss(this,\"towrite\")'>${code} ${mc}&nbsp;&nbsp;涨幅：${zf}% &nbsp;&nbsp;${lb}</a>"}, 					
				{"tag":"p", children:function(){
					var h1 = "";
					if(this.hsl != "无"){
						h1 = "<span style ='color:#F5F5F5'>换手率：</span>" + this.hsl;
					}
					var h2 = "";
					if(this.xgb != "无"){
						if(this.hsl != "无"){
							h2 = "<p><span style ='color:#F5F5F5'>选股宝：</span>" + this.xgb + "</p>";
						}
						else{
							h2 = "<span style ='color:#F5F5F5'>选股宝：</span>" + this.xgb;
						}
					}
					var h3 = "";
					if(this.rdjd != "无"){
						if(this.hsl != "无" || this.xgb != "无"){
							h3 = "<p><span style ='color:#F5F5F5'>热点解读：</span>" + this.rdjd + "</p>";
						}
						else{
							h3 = "<span style ='color:#F5F5F5'>热点解读：</span>" + this.rdjd;
						}						
					}						
					return(
						"<b><a style ='color:#FFF' href=http://www.treeid/code_" +
						this.code + " onclick='changeCss(this,\"towrite\")'>" + 
						this.code + "&nbsp;&nbsp;" + 						
						this.mc + "&nbsp;&nbsp;涨幅:" + 
						this.zf + "% &nbsp;&nbsp;" + this.lb + "</a></b>"+
						h1 + h2 + h3);
					}},					
				]}];
				
				var html = json2html.transform(html3, transform_aa);		
				div = document.getElementById('towrite');
				div.innerHTML = div.innerHTML + html.replace(/涨幅：%/g,"");
								
			}
			document.getElementById("PriceDate").value = tt;
		}
		</script>

	</head>

	<body>		
		<div id="towrite" class="fixedBox"></div>		
	</body>
</html>